package com.wordsay.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateTimeUtil {

	/**
	 * parse dateformat string to calendar object
	 * @param datetime
	 * @return
	 * @throws Exception
	 */
	public static Calendar converToCalender(String datetime) throws Exception{
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		Calendar cal = Calendar.getInstance();
		cal.setTime(df.parse(datetime));
		
		return cal;
	}
	
	public static String converToString(Calendar cal) throws Exception {
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(cal.getTime());
		
	}
	
	public static String getHour(Calendar calendar){
		
		return String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
	}
	
	public static String getWeekDay(Calendar calendar) {
		int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) -1;
		return String.valueOf(dayOfWeek);
		
	}
	
	public static String getDate(Calendar calendar){
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

		return df.format(calendar.getTime());
	}
}
